<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('图片视频上传示例列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="web:imageDemo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="web:imageDemo:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="web:imageDemo:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="web:imageDemo:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        <div class="enlarge_box" style="cursor:pointer;">
            <img id="enlarge_box_img" alt="" name="pic" src="" style="z-index: 99;">
        </div>
    </div>
</div>
<!--动态窗口-->
<div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close closeVideo" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">视频</h4>
                <small class="font-bold">
            </div>
            <div class="modal-body">
                <video id="play" th:src="${videoUrl}"></video>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white closeVideo" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('web:imageDemo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('web:imageDemo:remove')}]];
    var prefix = ctx + "web/imageDemo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "图片视频上传示例",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'image',
                    title: '单图片',
                    formatter: function (value, row, index) {
                        // return $.table.imageView(value,300,300);
                        return "<img class=\"img-clouds\" onclick=\"clouds(this)\" src=" + value + "  style=\" width:50px; height:50px;\">";
                    }
                },
                {
                    field: 'imagesStr',
                    title: '多图片',
                    formatter: function (value, row, index) {
                        if (value != null && value != "") {
                            var html = "";
                            for (var i = 0; i < value.length; i++) {
                                var one = '<img class="img-clouds" onclick="clouds(this)" src=' + value[i] + ' style=" width:80px; height:80px;"> ';
                                html += one;
                            }
                            return html;
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'video',
                    title: '单视频',
                    formatter: function (value, row, index) {
                        if (value != null && value != "") {
                            return '<button type="button" class="btn btn-primary" data-toggle="modal" onclick="openVideo(\'' + value + '\')" data-target="#myModal2">点击查看</button> '
                        }
                    }
                },
                {
                    field: 'videosStr',
                    title: '多视频',
                    formatter: function (value, row, index) {
                        if (value != null && value != "") {
                            var html = '';
                            for (var i = 0; i < value.length; i++) {
                                html += '<button type="button" class="btn btn-primary" data-toggle="modal" onclick="openVideo(\'' + value[i] + '\')" data-target="#myModal2">查看</button> '
                            }
                            return html;
                        } else {
                            return '';
                        }
                    }
                },
                {
                    field: 'createDate',
                    title: '创建时间'
                },
                {
                    field: 'lastDate',
                    title: '最后一次修改时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function openVideo(video) {
        var videoElem = document.getElementById("play");
        videoElem.src = video;
        // //视频自动播放
        videoElem.play();
    }

    // 点击关闭视频按钮
    $(function(){
        $(".closeVideo").click(function(){
            var videoElem = document.getElementById("play");
            videoElem.src = '';
        })
    })



    // 放大和隐藏图片
    function clouds(that) {
        $('.enlarge_box').show();
        let img_src = $(that).attr('src');
        let $preview = $('#enlarge_box_img').attr('src')
        if ($preview != img_src) {
            $('#enlarge_box_img').attr('src', img_src)
        }
        //获取图片大小
        let widthHtml = $('#enlarge_box_img').width();
        let heightHtml = $('#enlarge_box_img').height();
        let a_widthHtml = '-' + widthHtml / 2;
        let a_heightHtml = '-' + heightHtml / 2;
        //图片宽高比例
        let proportion = widthHtml / heightHtml;

        //获取浏览器可视区域大小
        let windowsWidth = $(window).width();
        let windowsHeight = $(window).height();
        let a_windowsWidth = windowsWidth * 0.8;
        let a_windowsHeight = windowsHeight * 0.8;
        let b_windowsWidth = '-' + a_windowsWidth / 2;
        let b_windowsHeight = "-" + a_windowsHeight / 2
        let a = "-" + proportion * a_windowsHeight / 2;

        if (widthHtml > a_windowsWidth || heightHtml > a_windowsHeight) {
            $('#enlarge_box_img').css({
                'height': a_windowsHeight + 'px',
                'position': 'fixed',
                'display': 'block',
                'left': 50 + '%',
                'margin-left': a + 'px',
                'top': 50 + '%',
                'margin-top': b_windowsHeight + 'px',
                'z-index': 9999,
            })
        } else {
            $('#enlarge_box_img').css({
                'position': 'fixed',
                'display': 'block',
                'left': 50 + '%',
                'margin-left': a_widthHtml + 'px',
                'top': 50 + '%',
                'margin-top': a_heightHtml + 'px',
                'z-index': 9999,
            })
        }
    }

    //点击放大后的图片隐藏
    $('.enlarge_box').click(function () {
        $('.enlarge_box').hide();
        $('#enlarge_box_img').attr('src', '')
        $('#enlarge_box_img').removeAttr("style")
    });
</script>
</body>
</html>